package org.bot.plugin.web.util;

import org.apache.http.client.CookieStore;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.BasicClientCookie;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;

import java.util.Set;

/**
 * @author 沧月
 * @create 0011 2023/10/11 17:01
 * @description <description class purpose>
 */
public class CookieBuild {

    public static CookieStore build(WebDriver webDriver) {
        Set<Cookie> cookies = webDriver.manage().getCookies();
        CookieStore cookieStore = new BasicCookieStore();
        for (Cookie seleniumCookie : cookies) {
            BasicClientCookie httpClientCookie = new BasicClientCookie(
                    seleniumCookie.getName(), seleniumCookie.getValue()
            );
            httpClientCookie.setDomain(seleniumCookie.getDomain());
            httpClientCookie.setPath(seleniumCookie.getPath());
            httpClientCookie.setExpiryDate(seleniumCookie.getExpiry());
            cookieStore.addCookie(httpClientCookie);
        }
        return cookieStore;
    }
}
